package com.shuzijun.leetcode.editor.cn;

import java.util.Stack;

public class DailyTemperatures{
    public static void main(String[] args) {
         Solution solution = new DailyTemperatures().new Solution();
         solution.dailyTemperatures(new int[]{73,74,75,71,69,72,76,73});
    }
    //leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public int[] dailyTemperatures(int[] t) {
        int n = t.length;
        int[] result = new int[n];
        Stack<Integer> stack = new Stack<>();
        for (int i = 0; i < n; i++) {
            while (!stack.empty() && t[stack.peek()] < t[i]){
                Integer idx = stack.peek();
                result[idx] = i-idx;
                stack.pop();
            }
            stack.push(i);
        }
        return result;
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}